#define  _CRT_SECURE_NO_WARNINGS 1
//#include <stdio.h>
//#include <string.h>
//
//#define max_candidates 5
//#define max_namelength 20
//
//typedef struct Candidate {
//    int no;
//    char name[max_namelength];
//    char sex[max_namelength];
//    int votes;
//    double rate;
//} Candidate;
//
//void Input(Candidate candidates[]) {
//    printf("Please enter the information of the candidates:\n");
//    for (int i = 0; i < max_candidates; i++) {
//        candidates[i].no = i + 1;
//        printf("Candidate %d:\n", candidates[i].no);
//        printf("Name: ");
//        scanf("%s", candidates[i].name);
//        printf("Sex: ");
//        scanf("%s", candidates[i].sex);
//        candidates[i].votes = 0;
//        candidates[i].rate = 0.0;
//    }
//}
//
//void Statis(Candidate candidates[]) {
//    int vote;
//    do {
//        printf("Please enter the candidate number (-1 to stop): ");
//        scanf("%d", &vote);
//        if (vote >= 1 && vote <= max_candidates) {
//            candidates[vote - 1].votes++;
//        }
//        else if (vote != -1) {
//            printf("Invalid candidate number!\n");
//        }
//    } while (vote != -1);
//
//    int validVotes = 0;
//    for (int i = 0; i < max_candidates; i++) {
//        validVotes += candidates[i].votes;
//    }
//
//    for (int i = 0; i < max_candidates; i++) {
//        candidates[i].rate = (double)candidates[i].votes / validVotes * 100;
//    }
//}
//
//void Sort(Candidate candidates[]) 
//{
//    for (int i = 0; i < max_candidates - 1; i++) 
//    {
//        int maxIndex = i;
//        for (int j = i + 1; j < max_candidates; j++) 
//        {
//            if (candidates[j].votes > candidates[maxIndex].votes ||
//                (candidates[j].votes == candidates[maxIndex].votes &&
//                    strcmp(candidates[j].name, candidates[maxIndex].name) < 0)) 
//            {
//                maxIndex = j;
//            }
//        }
//        Candidate temp = candidates[i];
//        candidates[i] = candidates[maxIndex];
//        candidates[maxIndex] = temp;
//    }
//}
//
//void Output(const Candidate candidates[]) 
//{
//    printf("Candidate information:\n");
//    printf("No\tName\tSex\tVotes\tRate\n");
//    for (int i = 0; i < max_candidates; i++) {
//        printf("%d\t%s\t%s\t%d\t%.2f\n", candidates[i].no, candidates[i].name,
//            candidates[i].sex, candidates[i].votes, candidates[i].rate);
//    }
//}
//
//int main() {
//    Candidate candidates[max_candidates];
//    Input(candidates);
//    Statis(candidates);
//    Sort(candidates);
//    Output(candidates);
//    return 0;
//}



#include<stdio.h>
#include<string.h>
#define N 3

struct candidate
{
	int no;
	char name[20];
	char sex[20];
	int votes;
	double rates;
};

void Input(struct candidate candidates[])
{
	int i;
	printf("no  name  sex\n");
	for (i = 0; i < N; i++)
	{
		scanf("%d%s%s", &candidates[i].no, candidates[i].name, candidates[i].sex);
		candidates[i].votes = 0;
		candidates[i].rates = 0.0;
	}
}

void Statis(struct candidate candidates[])
{
	int vote, i;
	do
	{
		scanf("%d", &vote);
		if (vote >= 1 && vote <= 5)
		{
			candidates[vote - 1].votes++;
		}
		else if (vote != -1)
		{
			printf("Invalid!\n");
		}
	} while (vote != -1);

	int s = 0;
	for (i = 0; i < N; i++)
	{
		s = s + candidates[i].votes;
	}
	for (i = 0; i < N; i++)
	{
		candidates[i].rates = candidates[i].votes / (double)s*100;
	}

}

void Sort(struct candidate candidates[])
{
	int i, j;
	struct candidate temp;
	for (i = 0; i < N - 1; i++)
	{
		for(j=0;j<N-1-i;j++)
			if (candidates[j].rates < candidates[j + 1].rates ||
				(candidates[j].rates == candidates[j + 1].rates && strcmp(candidates[j].name, candidates[j + 1].name) > 0))
			{
				temp = candidates[j];
				candidates[j] = candidates[j + 1];
				candidates[j + 1] = temp;
			}
	}

}

void Output(struct candidate candidates[])
{
	int i;
	printf("no\tname\tsex\tvotes\trates\n");
	for (i = 0; i < N; i++)
	{
		printf("%d\t%s\t%s\t%d\t%.2lf\n",
			candidates[i].no, candidates[i].name, candidates[i].sex, candidates[i].votes, candidates[i].rates);
	}
}

int main()
{
	struct candidate candidates[N];
	Input(candidates);
	Statis(candidates);
	Sort(candidates);
	Output(candidates);

	return 0;
}

//1 jack male
//2 mary female
//3 mike male